package com.organ.base.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.organ.base.entity.SysAttribute;
import com.organ.base.service.SysAttributeService;
import com.organ.base.util.Pager;
import com.organ.base.util.R;

import lombok.AllArgsConstructor;

@Controller
@AllArgsConstructor
@RequestMapping("/soldier")
public class SysAttributeController {
	private final SysAttributeService soldierAttributeService;
	
	/**
	 * soldier/page
	 * @param 分页查询
	 * @param page    分页对象
	 * @param sysFile 文件管理
	 * @return
	 */
	@ResponseBody
	@GetMapping("/page")
	public R getSoldierAttributePage(Page page, SysAttribute soldierAttribute) {
		return R.ok(soldierAttributeService.page(page, Wrappers.query(soldierAttribute)));
	}
	/**
	 * soldier/findSoldierAttribute
	 * @param map
	 * @return
	 */
	@GetMapping(value="/findSoldierAttribute/{sysType}")
	public String findGradeHistory(HttpServletRequest req,Integer pageIndex,ModelMap map,@PathVariable("sysType") String sysType){
		
		if(pageIndex == null){
			pageIndex = 1;
		}
		Integer pageSize=12;
		
		Pager<SysAttribute> pager=new Pager<SysAttribute>();
		pager.setPageIndex(pageIndex);
		pager.setPageSize(pageSize);
		Integer pageBegin=(pageIndex - 1) * pageSize;
		List<SysAttribute> salist =soldierAttributeService.finSysAttributeBytype(pageBegin, pageSize,sysType);
		pager.setList(salist);
		//查询总数
		pager.setTotalRecords(soldierAttributeService.findCountsSysAttributeBytype(sysType));
		pager.setTotalPages();//设置总页数
		map.addAttribute("pager",pager);
		return "soldier";
	}
}
